package com.test;

import java.util.Arrays;

/**
 * @Auther: ChenJinEn
 * @Date: 2020/6/9 20:26
 * @Description: //TODO
 */
public class PrintDemo {

    public static void main(String[] args) {
    /*
     Object的hashCode()默认是返回内存地址的，但是hashCode()可以重写，所以hashCode()不能代表内存地址的不同。
    System.identityHashCode(Object)方法可以返回对象的内存地址,不管该对象的类是否重写了hashCode()方法
    */
        String s = new String("你好");
        String ss = "你好";
        String sss =  "你好";
        Long a = new Long(3);
        Long b = 3L;
        int c = 3;
        byte i = 3;
        short k = 3;
        float j = 3.0f;
        long d = c;//不同数据类型,基本数据赋值是赋值一份字面量,是赋值
        long l = 3;
        int e = 3;
        int f = 4;
        c=f;//相同数据类型,基本数据类型是赋值地址值,是赋予地址


        //基本数据类型比较的是值,字面量的相等,引用数据类型比较的是地址相等
        System.out.println(c == j);//false
        System.out.println(a == b);//false
        System.out.println(b == c);//false
        System.out.println(c == b);//false
        System.out.println(d == c);//false
        System.out.println(c == i);//false
        System.out.println(c == k);//false
        System.out.println(d == l);//true
        System.out.println(b == d);//true

        //基本数据类型也会开辟空间,也会有地址值,定义一次重复使用,只不过它是在栈内存中开辟
        System.out.println(System.identityHashCode(c));
        System.out.println(System.identityHashCode(i));
        System.out.println(System.identityHashCode(f));
        System.out.println(System.identityHashCode(e));
        System.out.println(System.identityHashCode(d));

       /* 字符串常量也是一次定义多次使用,内存地址是不一样的但是重写了hashcode和equals方法
        认定同一字符串的hashcode算法算出的值是一样的*/
        System.out.println(a.hashCode()+" "+System.identityHashCode(a));
        System.out.println(b.hashCode()+" "+System.identityHashCode(b));
        System.out.println(s.hashCode()+" "+System.identityHashCode(s));
        System.out.println(ss.hashCode()+" "+System.identityHashCode(ss));
        System.out.println(sss.hashCode()+" "+System.identityHashCode(sss));

        //这里是比较字符串地址
        System.out.println(s == ss);
        System.out.println(ss == sss);

    }

    private static void 冒泡2() {
        int[] array={1,5,33,7,8,27,5,90,2,6,25};


        for (int i = 0; i < array.length; i++) {
            //取出一个元素,与它前面所有数组元素作对比
            for (int j = 0; j < i ; j++) {
                if(array[i] < array[j]){
                    int t = array[j];
                    array[j] = array[i];
                    array[i] = t;
                }

            }
        }
        for (int i = 0; i < array.length-1; i++) {
            //取出除最后一位元素分别与该元素的后面所有的数组元素作对比
            for (int j = i+1; j < array.length ; j++) {
                if(array[i] < array[j]){
                    int t = array[j];
                    array[j] = array[i];
                    array[i] = t;
                }

            }
        }

        System.out.println(Arrays.toString(array));
    }

    private static void sada() {
        int[] arr = {1,2,3,4,5};
        int[] ints = new int[5];
        for (int i = arr.length - 1; i >= 0; i--) {
            ints[i]=arr[arr.length-1-i];
        }
        System.out.println(Arrays.toString(ints));
    }

    private static void sad() {
        String a = "ABCD";
        String b = a.toLowerCase();
        b.replace('a', 'd');
        b.replace('b', 'c');
        System.out.println(b);
        /*
        原以为结果dccd,结果abcd,String里面的方法修改原对象都会创建新字符串
        而StringBuffer中的方法修改字符串操作的都是同一对象
         */
    }

    private static void 坑题1() {
        String foo = "blue";
        String bar = foo;
        foo = "green";
        //String bar = foo;代码由上而下执行,在这行引用地址才会改变啊
        System.out.println(bar);
    }

    private static void xx() {
        int i = 1, j= 10;
        do{
            if (i>j){
                break;
            }
            j--;
        }while (++i<5);
        System.out.println("i="+i+"j="+j);
    }

    private static void switchtest() {
    /*
     switch支持的数据类型只有整型(byte short int)、字符(char)、枚举型、(布尔在c语言中是可以的)

     java 1.6(包括)以前，只是支持等价bai成int 基本类型的数据du:byte ,short,int,char(其他的zhi都不可dao以）。
     1.7加入的新特性可以支持String类型的数据。long是不可以的。。就算是通过强制的转化也必须是转成int。

     switch与if-else的区别：
     switch建议判断固定值的时候用；
     if建议判断区间或范围的时候用；   
     用switch能做的，用if都能做，但是反过来则不行。
     */
    }

    private static void hh() {
        Object o1 = 3;
        Object o2 = new Integer(3);
        Object o3 = new Integer[3];
        Object o4 = new int[3];
        Object o5 = new Object();
        Object o6 = new Object[3];
    }

    private static void 易错题() {
        int x = 4;
        int result = (x++)/3;//"/"求整数倍数部分,"%"求余数部分
        System.out.println(result);//面试我居然写了2/3,真的瞎
    }

    private static void 等腰梯形() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i+3;j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    private static void 空心倒三角() {
        for (int i = 5; i >=1; i--) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
                if(i==1||i==5){
                    System.out.print("*");
                }else if (j==1||j==2*i-1){
                    System.out.print("*");
                }else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    private static void 空心等腰三角形() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
                if(i==1||i==5){
                    System.out.print("*");
                }else if (j==1||j==2*i-1){
                    System.out.print("*");
                }else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    private static void 打印空心棱形() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
               if (j==1||j==2*i-1){
                   System.out.print("*");
               }else {
                   System.out.print(" ");
               }
            }
            System.out.println();
        }
        for (int i = 4; i >= 1; i--) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
                if (j==1||j==2*i-1){
                    System.out.print("*");
                }else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    private static void 打印实心棱形() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = 4; i >= 1; i--) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= 2*i-1;j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    private static void 平行四边形() {
        for (int i = 0; i < 4; i++) {
            for (int j = 4; j > i; j--) {
                System.out.print(" ");
            }
            for (int i1 = 0; i1 < 4; i1++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    private static void 直角三角形() {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4-i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    private static Float aa() {
        return 0f;
    }

    private static void printzfx() {
        System.out.println("打印正方形");
        for(int i=1;i<=9;i++){
            for(int j=1;j<=9;j++){
                System.out.print("*\t");
            }
            System.out.println();
        }
    }


    private static void prin1() {
        System.out.println("九九乘法口诀");
        for(int i=1;i<=9;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j+"*"+i+"="+(i*j)+"  ");
            }
            System.out.println();
        }
    }
}
